﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using Foothill.Model;
using Foothill.Common;

namespace Foothill.Model.Test
{
    [TestFixture]
    public class AddConditionIdFilterItemTest
    {
        [Test]
        public void ConditionShouldBeSetToNew_WhenAddingNewToBoth()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Both };
            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.New };
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.New, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToUsed_WhenAddingUsedToBoth()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Both };
            AdCategorySelectItem usedCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.Used };
            param.AddFilterItem(usedCondition);

            Assert.AreEqual((int)VehicleCondition.Used, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToBoth_WhenAddingUsedToNew()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.New };

            AdCategorySelectItem usedCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.Used };
            param.AddFilterItem(usedCondition);

            Assert.AreEqual((int)VehicleCondition.Both, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToBoth_WhenAddingNewToUsed()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Used };

            AdCategorySelectItem usedCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.New };
            param.AddFilterItem(usedCondition);

            Assert.AreEqual((int)VehicleCondition.Both, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToBoth_WhenRemovingNewFromNew()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.New };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Remove, SelectedIdValue = (int)VehicleCondition.New };
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.Both, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToBoth_WhenRemovingUsedFromUsed()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Used };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Remove, SelectedIdValue = (int)VehicleCondition.Used };
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.Both, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToNew_WhenRemovingUsedFromBoth()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Both };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Remove, SelectedIdValue = (int)VehicleCondition.Used };
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.New, param.ConditionId);
        }

        [Test]
        public void ConditionShouldBeSetToUsed_WhenRemovingNewFromBoth()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Both };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Remove, SelectedIdValue = (int)VehicleCondition.New};
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.Used, param.ConditionId);
        }

        [Test]
        public void ConditionShouldRemainUsed_WhenAddUsedToUsed()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.Used };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.Used };
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.Used, param.ConditionId);
        }

        [Test]
        public void ConditionShouldRemainNew_WhenAddNewToNew()
        {
            ForSaleAdAdvancedSearchParameter param = new ForSaleAdAdvancedSearchParameter { ConditionId = (int)VehicleCondition.New };

            AdCategorySelectItem newCondition = new AdCategorySelectItem() { Category = AdListCategory.Condition, Action = SelectItemAction.Add, SelectedIdValue = (int)VehicleCondition.New};
            param.AddFilterItem(newCondition);

            Assert.AreEqual((int)VehicleCondition.New, param.ConditionId);
        }
    }
}
